//
//  PowerBatteryAlertController.swift
//  DaRings
//
//  Created by 尹琼 on 2022/12/14.
//

import UIKit
import MYModule

open class BluetoothAlertController: ViewController {
    
    public  var popupView = AchievedGoalPopupView()
    
    public var type: BluetoothAlertType
    
    public var dataString: String
    
    private var handler: (() ->Void)?
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public init(type: BluetoothAlertType, dataString: String, handler: (() ->Void)? = nil) {
        self.type = type
        self.dataString = dataString
        self.handler = handler
        super.init(nibName: nil, bundle: nil)
        
        modalType()
    }
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        
       
    }
    
    open func modalType() {
         
        definesPresentationContext = true
        modalPresentationStyle = .overCurrentContext
        modalTransitionStyle = .crossDissolve
        view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
         
     }
    
    open override func makeUI() {
        super.makeUI()
        
        popupView.iconImageView.image = UIImage(named: type.imageName)
        popupView.titleLabel.text = type.title
        popupView.subtitleLabel.attributedText = type.attributedString(value: dataString)
       
        popupView.okButton.backgroundColor = type.tintColor
        
        view.addSubview(popupView)
        
        popupView.snp.makeConstraints { make in
            make.center.equalToSuperview()
        }
        
        switch type {
        case .heartRate:
            popupView.type = .highHeartRate
            break
        case .sedentary:
            popupView.type = .sedentaryReminder
            break
        case .lowPowerBettry:
            popupView.type = .lowBattery
            break
        case .trainingGoal:
            popupView.type = .singleGoal
            break
        case .activityStepGoal, .activityCaloriesGoal, .activityTimeGoal:
            popupView.type = .trainingGoal
            break
        case .gpsTrainingGoal:
            popupView.type = .singleGoal
        }
        
        self.popupView.okButton.rx.tap.subscribe(onNext: {[weak self] in
            
            self?.dismiss(animated: true, completion: self?.handler)
            
        }).disposed(by: rx.disposeBag)
        
    }
    

}
